import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'Home',
    component: Home,
    children: [{
        path: "/",
        name: "Shouye",
        component: () => import('../views/shouye.vue'),
        children: [{
            path: '/',
            name: 'houtaishouye',
            component: () => import('../views/houtaishouye.vue')
          },
          {
            path: '/xiangceguanli',
            name: 'xiangceguanli',
            component: () => import('../views/xiangceguanli.vue')
          },
          {
            path: '/shangpinlist',
            name: 'shangpinlist',
            component: () => import('../views/shangpinlist.vue')
          },
        ]
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import('../views/goods.vue'),
        children: [{
            path: '/goods',
            name: 'goodsList',
            component: () => import('../views/goodsList.vue'),
          },
          {
            path: '/feilei',
            name: 'feilei',
            component: () => import('../views/feilei.vue'),
          }
        ]
      },
      {
        path: '/order',
        name: 'order',
        component: () => import('../views/order.vue'),
        children: [{
          path: '/order',
          name: 'orderData',
          component: () => import('../views/orderData.vue'),
        }]
      },
      {
        path: '/vip',
        name: 'vip',
        component: () => import('../views/vip.vue'),
        children: [{
          path: '/vip',
          name: 'vipList',
          component: () => import('../views/vipList.vue')
        },
        {
          path: '/vipDengji',
          name: 'vipDengji',
          component: () => import('../views/vipDengji.vue')
        },
      ]
      },
      {
        path: '/shezhi',
        name: 'shezhi',
        component: () => import('../views/shezhi.vue'),
        children:[
          {
            path: '/shezhi',
            name: 'jichushezhi',
            component: () => import('../views/jichushezhi.vue'),
          },
          {
            path: '/wuliushezhi',
            name: 'wuliushezhi',
            component: () => import('../views/wuliushezhi.vue'),
          },
          {
            path: '/guanliyuan',
            name: 'guanliyuan',
            component: () => import('../views/guanliyuan.vue'),
          },
          {
            path: '/jiaoyishezhi',
            name: 'jiaoyishezhi',
            component: () => import('../views/jiaoyishezhi.vue'),
          }
        ]
      }
    ]
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/login', //登录页面
    name: 'Login',
    component: () => import('../views/Login.vue')
  }
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
var Token  = localStorage.getItem('token')
if(to.name==='Login'){
  next()
}else if(Token){
  next()
}else{
  next('/login')
}
})

export default router